archiveArtifacts
The archiveArtifacts step is used to persist build outputs after a pipeline finishes.
It is one of the most important steps for reporting, debugging, and auditing.
What Does archiveArtifacts Do?β
archiveArtifacts:
- Copies files from the workspace
- Stores them with the build record
- Makes them available after build completion
Artifacts are stored on the controller, not the agent.
Basic Usageβ
post {
always {
archiveArtifacts artifacts: '**/target/*.jar'
}
}
This archives all JAR files under target directories.
Where Artifacts Liveβ
- Artifacts are attached to a specific build
- Accessible via Jenkins UI
- Downloadable anytime (based on retention)
Wildcards & Patternsβ
Common patterns:
**/*.log**/reports/**target/*.jar
Use precise patterns to avoid large uploads.
Allow Empty Archivesβ
archiveArtifacts artifacts: 'reports/**', allowEmptyArchive: true
Useful when:
- Reports are generated conditionally
- You donβt want pipeline failure
Retention & Cleanupβ
Artifacts are affected by:
- Build discarder settings
- Disk usage limits
Always configure log rotation.
archiveArtifacts vs stashβ
| Feature | archiveArtifacts | stash |
|---|---|---|
| Purpose | Persist results | Share data |
| Scope | Across builds | Within pipeline |
| Stored on | Controller | Controller |
| Retained | Yes | No (temporary) |
Common Mistakesβ
- Archiving entire workspace
- No build discarder configured
- Confusing stash with archive
- Archiving secrets accidentally
Best Practicesβ
- Archive only what you need
- Use post block
- Keep artifact size small
- Combine with buildDiscarder
Interview Trapsβ
-
Where are artifacts stored?
β Controller -
Do artifacts persist after build?
β Yes -
Can artifacts be used across jobs?
β Yes (via Copy Artifacts)